/**
 * Created by a1 on 16/4/27.
 */
$(document).ready(function() {
    $("#load").click(function() {
        load()
    })
    $("#load2").click(function() {
        loadWithJQuery()
    })
    $("#load3").click(function() {
        get()
    })
})
//var url = "http://www.weather.com.cn/data/cityinfo/101010100.html"
//var url = "http://www.w3school.com.cn/ajax/demo_get.asp"
var url = "../resource/txt"


function load() {
    //alert("load")
    var request = new XMLHttpRequest()
    request.onreadystatechange = function() {
        //alert("state = " + request.readyState + "status = " + request.status)
        if(request.readyState == 4) {
            if(request.status == 0 || request.status == 200) {
                $("#weather").text(request.responseText)
            }
        }
    }

    request.open("Get", url, true)
    request.send()
}

function loadWithJQuery() {
    //alert("load")
    $('#weather').load(url)
}

function get() {
    //$.getJSON(url, function(data, status) {
    //    alert("json = " + data.text)
    //    $('#weather').text(data.a + data['b'] + data.c)
    //})

    $.get(url, function(data, status) {
        //$('#weather').text(data)
        alert("text = " + data)
        var json = eval('('+data+')')
        $('#weather').text(json.a + json['b'] + json.c)
        //$('#weather').text(json['c'])
    })
}

